package com.koron.order.concession.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.util.CheckPermission;
import com.koron.order.concession.bean.dto.ConcessionDto;
import com.koron.order.concession.bean.po.ConcessionPo;
import com.koron.order.concession.bean.query.ConcessionQuery;
import com.koron.order.concession.bean.vo.ConcessionVo;
import com.koron.order.concession.service.ConcessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 让步接收单信息主表(Concession)表控制层
 *
 * @author zhouj
 * @since 2022-01-14 09:51:55
 */
@Api(tags = "让步接收单信息主表(Concession)")
@RestController
@RequestMapping("/concession/")
public class ConcessionController {

    @Autowired
    private ConcessionService concessionService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改让步接收单信息主表")
    @PostMapping("insertOrUpdate")
    public Response<ConcessionPo> insertOrUpdate(@Validated @RequestBody ConcessionDto concessionDto) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "insertOrUpdate", ConcessionPo.class, concessionDto));
    }

    @ApiOperation(value = "根据id删除让步接收单信息主表")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询让步接收单信息主表")
    @CheckPermission
    @GetMapping("queryById")
    public Response<ConcessionPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "queryById", ConcessionPo.class, id));
    }

    @ApiOperation(value = "不分页查询让步接收单信息主表列表")
    @GetMapping("queryList")
    public Response<List<ConcessionVo>> queryList(ConcessionQuery concessionQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "queryList", List.class, concessionQuery));
    }

    @ApiOperation(value = "分页查询让步接收单信息主表列表")
    @GetMapping("queryPageList")
    public Response<PageInfo> queryPageList(ConcessionQuery concessionQuery, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "queryPageList", PageInfo.class, concessionQuery, pageQuery));
    }

    @ApiOperation(value = "提交")
    @GetMapping("submitConcession")
    public Response<Integer> submitConcession(String orderId, String status) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), concessionService, "submitConcession", Integer.class, orderId, status));
    }

}
